<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: pending.class.php 47086 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
  defined('PHPFOX') or exit('NO DICE!');
  class Follow_Component_Block_Pending extends Phpfox_Component
  {
      public function process()
      {
            Phpfox::isUser(true);
            $bIsCurrentUser = false;
            $iPage = $this->getParam('page', 1);
            $sKeyword = $this->getParam('keyword', '');
            $iOffset = ($iPage - 1) * phpfox::getParam('follow.showeachtime');
            $sType = $this->getParam('type_id', 'user');
            if($sType == 'user')
            {
                if(!$aItem = $this->getParam('aUser'))
                {
                    $aItem = Phpfox::getService('user')->get(Phpfox::getUserId());
                    $bIsCurrentUser = true;
                }
            }
            else
            {
                if(!Phpfox::hasCallback($sType, 'getActivityFeed') || !$aParentModule = $this->getParam('aParentModule', false))
                {
                    return false;
                }
                $aItem = Phpfox::callback($sType . '.getActivityFeed', $aParentModule, null, true);
                if($sType == 'pages')
                {
                    if(Phpfox::getService('pages')->isAdmin($aParentModule['item_id']))
                    {
                        $bIsCurrentUser = true;
                    }
                }
                else
                {
                    if($aItem['user_id'] == Phpfox::getUserId())
                    {
                        $bIsCurrentUser = true;
                    }
                }
            }
            
            $aItem['item_id'] = $aItem[(($sType == 'pages') ? 'page': $sType).'_id'];
            $oProcess = Phpfox::getService('follow.process');
            $aSetting = $oProcess->getSetting(Phpfox::getUserId(), $sType);
            $aResult = array();
            $sKeyword = '';
            $iTotalPending = 0;
            $aPendings = $this->getParam('aItems', array());
            
            if(!$sKeyword = $this->getParam('sKeyword'))
            {
                list($iTotalPending, $aPendings) = Phpfox::getService('follow')->getPending($sKeyword, $aItem[(($sType == 'pages') ? 'page': $sType).'_id'] , $iOffset, Phpfox::getParam('follow.showeachtime'), $sType);
            }
            if(!empty($aPendings))
            {
                foreach($aPendings as $aUser)
                {
                    $aResult[] = phpfox::getService('user')->get($aUser['user_id']);
                }
            }
            
         $this->template()->assign(array(
            'aPendings' => $aPendings,
            'aItem' => $aItem,
            'sType' => $sType,
            'aSetting' => $aSetting,
            'iTotalPending' => $iTotalPending
         )); 
      }
  }
?>
